<?php

namespace app\apiv1\controller;

use service\DataService;
use think\Error;
use think\Validate;
use think\Db;
use think\Facade\Cache;

/**
 * 应用入口控制器
 * @author Anyon <zoujingli@qq.com>
 */
class C2c extends Base
{
    //获取订单信息
    public function getC2cOrderDetail()
    {
        $orderId = input('post.orderId');
        !$orderId && $this->error('订单ID不能为空');
        //20001 没有撮合  20002  撮合了  20003 已经完成
        $orderInfo = Db::name('store_member a')
            ->field('a.id,a.phone,a.account_money,b.num,b.real_price,b.order_no,b.create_at,b.status,b.price,b.dakuan_image')
                ->join("store_order_c2c b", "a.id = b.mid")
            ->where(['b.id' => $orderId])
            ->find();
        switch ($orderInfo['status']){
            case 1:
                $this->success('', ['status'=>$orderInfo['status'],'orderInfo'=>$orderInfo]);
                break;
            case 2:
                unset($orderInfo);
                $orderInfo = Db::name('store_member a')
                    ->field('a.id,a.phone,a.account_money,b.num,b.real_price,b.price,b.order_no,b.create_at,b.end_time,b.mid,b.type,b.id as orderid,b.interval_id,b.status')
                    ->join("store_order_c2c b", "a.id = b.mid")
                    ->where(['b.id' => $orderId])
                    ->find();
                $orderInfo['interval_info'] = Db::name('store_order_interval')->where(['id' => $orderInfo['interval_id']])->value('title');
                $info = Db::name('store_member a')
                    ->field('a.id,a.phone,a.account_money,b.num,b.real_price,b.order_no,b.create_at,b.mid,b.type,b.id as orderid,b.dakuan_image')
                    ->join("store_order_c2c b", "a.id = b.mid")
                    ->where(['b.other_order_id' => $orderId])
                    ->find();
                $orderInfo['phone'] = $info['phone'];
                $orderInfo['dakuan_image'] = $info['dakuan_image'];
                $orderInfo['payment_zfb'] = Db::name('store_member_payment')->where(['uid' => $info['mid'], 'type' => 2])->find();
                $orderInfo['payment_wexin'] = Db::name('store_member_payment')->where(['uid' => $info['mid'], 'type' => 1])->find();
                $orderInfo['payment_bank'] = Db::name('store_member_bank')->where(['uid' => $info['mid']])->find();
                $orders = Db::name('store_order_c2c')->where(['id' => $orderId])->find();
                if ($orders['type'] == 1) {
                    //买入订单
                    $daon = Db::name('store_c2c_relation')->where(['orderid' => $orderId])->find();
                } elseif ($orders['type'] == 2) {
                    //卖出订单 的交易时间
                    $daon = Db::name('store_c2c_relation')->where(['orderid' => $orders['other_order_id']])->find();
                }
                $orderInfo['countdown'] = $daon['create_at'] + 3600 * 24 - get_time();
                if($orderInfo['type'] == 2){
                    $this->success('', ['status'=>5,'orderInfo'=>$orderInfo]);
                }
                $this->success('', ['status'=>$orderInfo['status'],'orderInfo'=>$orderInfo]);
                break;
            case 3:
                unset($orderInfo);
                $orderInfo = Db::name('store_member a')
                    ->field('a.id,a.phone,a.account_money,b.num,b.real_price,b.price,b.order_no,b.create_at,b.end_time,b.mid,b.type,b.id as orderid,b.interval_id,b.status')
                    ->join("store_order_c2c b", "a.id = b.mid")
                    ->where(['b.id' => $orderId])
                    ->find();
                $orderInfo['interval_info'] = Db::name('store_order_interval')->where(['id' => $orderInfo['interval_id']])->value('title');
                $info = Db::name('store_member a')
                    ->field('a.id,a.phone,a.account_money,b.num,b.real_price,b.order_no,b.create_at,b.mid,b.type,b.id as orderid,b.dakuan_image')
                    ->join("store_order_c2c b", "a.id = b.mid")
                    ->where(['b.other_order_id' => $orderId])
                    ->find();
                $orderInfo['phone'] = $info['phone'];
                $orderInfo['dakuan_image'] = $info['dakuan_image'];
                $orderInfo['payment_zfb'] = Db::name('store_member_payment')->where(['uid' => $info['mid'], 'type' => 2])->find();
                $orderInfo['payment_wexin'] = Db::name('store_member_payment')->where(['uid' => $info['mid'], 'type' => 1])->find();
                $orderInfo['payment_bank'] = Db::name('store_member_bank')->where(['uid' => $info['mid']])->find();
                $orders = Db::name('store_order_c2c')->where(['id' => $orderId])->find();
                if ($orders['type'] == 1) {
                    //买入订单
                    $daon = Db::name('store_c2c_relation')->where(['orderid' => $orderId])->find();
                } elseif ($orders['type'] == 2) {
                    //卖出订单 的交易时间
                    $daon = Db::name('store_c2c_relation')->where(['orderid' => $orders['other_order_id']])->find();
                }
                $orderInfo['countdown'] = $daon['create_at'] + 3600 * 24 - get_time();
                $this->success('', ['status'=>4,'orderInfo'=>$orderInfo]);
            case 4:
                unset($orderInfo);
                $orderInfo = Db::name('store_member a')
                    ->field('a.id,a.phone,a.account_money,b.num,b.real_price,b.price,b.order_no,b.create_at,b.end_time,b.mid,b.type,b.id as orderid,b.interval_id,b.status')
                    ->join("store_order_c2c b", "a.id = b.mid")
                    ->where(['b.id' => $orderId])
                    ->find();
                $orderInfo['interval_info'] = Db::name('store_order_interval')->where(['id' => $orderInfo['interval_id']])->value('title');
                $info = Db::name('store_member a')
                    ->field('a.id,a.phone,a.account_money,b.num,b.real_price,b.order_no,b.create_at,b.mid,b.type,b.id as orderid,b.dakuan_image')
                    ->join("store_order_c2c b", "a.id = b.mid")
                    ->where(['b.other_order_id' => $orderId])
                    ->find();
                $orderInfo['phone'] = $info['phone'];
                $orderInfo['dakuan_image'] = $info['dakuan_image'];
                $orderInfo['payment_zfb'] = Db::name('store_member_payment')->where(['uid' => $info['mid'], 'type' => 2])->find();
                $orderInfo['payment_wexin'] = Db::name('store_member_payment')->where(['uid' => $info['mid'], 'type' => 1])->find();
                $orderInfo['payment_bank'] = Db::name('store_member_bank')->where(['uid' => $info['mid']])->find();
                $orders = Db::name('store_order_c2c')->where(['id' => $orderId])->find();
                if ($orders['type'] == 1) {
                    //买入订单
                    $daon = Db::name('store_c2c_relation')->where(['orderid' => $orderId])->find();
                } elseif ($orders['type'] == 2) {
                    //卖出订单 的交易时间
                    $daon = Db::name('store_c2c_relation')->where(['orderid' => $orders['other_order_id']])->find();
                }
                $orderInfo['countdown'] = $daon['create_at'] + 3600 * 24 - get_time();
                if($orderInfo['type'] == 2){
                    $this->success('', ['status'=>6,'orderInfo'=>$orderInfo]);
                }
                $this->success('', ['status'=>3,'orderInfo'=>$orderInfo]);
                break;
            case 6:
                $this->success('', ['status'=>7,'orderInfo'=>$orderInfo]);
                break;
            case 7:
                $this->success('', ['status'=>8,'orderInfo'=>$orderInfo]);
        }

    }

}